package util;

import java.io.IOException;

import org.apache.log4j.Logger;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import pojo.Protocol;

public class ProtocolJSONConverter {
	
	private static final Logger LOGGER = Logger.getLogger(ProtocolJSONConverter.class);
	
	private static ObjectMapper mapper = new ObjectMapper();

	public static String toJSON(Protocol protocol) {
		String result = null;
		try {
			result = mapper.writeValueAsString(protocol);
		} catch (JsonProcessingException e) {
//			e.printStackTrace();
			LOGGER.error(e.toString());
		}
		return result;
	}
	
	public static Protocol toProtocol(String json) {
		Protocol protocol = null;
		try {
			protocol = mapper.readValue(json, Protocol.class);
		} catch (IOException e) {
//			e.printStackTrace();
			LOGGER.error(e.toString());
		}
		return protocol;
	}
}
